﻿<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<title>Web报表(B/S报表)演示 - 自定义分组报表</title>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
	<script src="../../CreateControl.js" type="text/javascript"></script>
	<script type="text/javascript">
var Report;
var CustomDrawBox;

function window_onload() 
{
    ReportViewer.Stop();
    
    Report = ReportViewer.Report;
    
    Report.OnControlCustomDraw = OnControlCustomDraw; //关联报表事件，响应部件框自定义绘制事件
        
    CustomDrawBox = Report.ControlByName("StaticBox2");
    CustomDrawBox.CustomDrawScript = ""; //将报表模板中的报表脚本代码去掉，让 OnControlCustomDraw 函数完成相同的任务

    //启动报表运行
    ReportViewer.Start();
}

function OnControlCustomDraw(Sender, Graphics, x, y, width, height)
{
	if ( Sender.EqualTo(CustomDrawBox) )
	{
        var pic = Report.Utility.CreatePicture(); //创建图像对象
        var Binary = Report.Utility.CreateBinaryObject();

        //用当前记录号模拟出一些条件参数
        var RecordNo = Report.SystemVarValue(4);  //GRSystemVarType.grsvRecordNo 当前记录号
        var ImageCount = (RecordNo-1)%3 + 1; //图像幅数

        var x = Graphics.Left;
        var y = Graphics.Top;
        var width = (Graphics.Width - ImageCount*8 + 8) / ImageCount;
        var height = Graphics.Height;

        Binary.LoadFromField( Report.FieldByName("Picture") ); //从字段中载入图像
        pic.LoadFromBinary(Binary); //载入图像
        Report.Graphics.DrawPicture(pic, x, y, width, height, 3, 2, 1);

        if (ImageCount >= 2)
        { 
          pic.LoadFromFile("C:\\Grid++Report 6\\Samples\\Data\\Picture\\" + Report.FieldByName("PictureFile").AsString + ".bmp"); //从文件中载入图像，PictureFile字段中存储图像文件的名称 
          x += width + 8;
          Report.Graphics.DrawPicture(pic, x, y, width, height, 3, 2, 1);
        }

        if (ImageCount == 3)
        { 
          //绘制报表图像集合中的图像，根据当前记录号确定图像序号
          var ImageIndex = Report.SystemVarValue(4)%5 + 1;  //GRSystemVarType.grsvRecordNo
          pic = Report.ImageList.Item(ImageIndex);
          x += width + 8;
          Report.Graphics.DrawPicture(pic, x, y, width, height, 3, 2, 1);
        }
	}
}
    </script>
    <style type="text/css">
        html,body {
            margin:0;
            height:100%;
        }
    </style>
</head>
<body style="margin:0" onload="return window_onload()">
	<script type="text/javascript"> 
		//CreatePrintViewerEx("100%", "100%", "../../../grf/7-3d.grf", "../../../data/DataCenter.jsp?data=Categories", false, "");
		CreateDisplayViewerEx("100%", "100%", "../../../grf/7-3d.grf", "../../../data/DataCenter.jsp?data=Categories", false, "");
	</script>
</body>
</html>
